package chixing.day11.clone_demo;

public class Student {
    private int stuId;
    private String stuName;
    private int stuAge;
    private Course course;
    public Student (){}

    public Student(int stuId, String stuName, int stuAge, Course course) {
        this.stuId = stuId;
        this.stuName = stuName;
        this.stuAge = stuAge;
        this.course = course;
    }
//深克隆：克隆的对象的属性，基本数据类型，直接复制旧对象的，引用数据类型的属性，该类型还要自己克隆一份给该属性
    @Override
    protected Object clone() throws CloneNotSupportedException {
        Student newStu = new Student();
        newStu.stuName = this.stuName;
        newStu.stuId = this.stuId;
        newStu.stuAge = this.stuAge;
        newStu.course =(Course) this.course.clone();
        return super.clone();
    }

    public int getStuId() {
        return stuId;
    }

    public void setStuId(int stuId) {
        this.stuId = stuId;
    }

    public String getStuName() {
        return stuName;
    }

    public void setStuName(String stuName) {
        this.stuName = stuName;
    }

    public int getStuAge() {
        return stuAge;
    }

    public void setStuAge(int stuAge) {
        this.stuAge = stuAge;
    }

    public Course getCourse() {
        return course;
    }

    public void setCourse(Course course) {
        this.course = course;
    }

    @Override
    public String toString() {
        return "Student{" +
                "stuId=" + stuId +
                ", stuName='" + stuName + '\'' +
                ", stuAge=" + stuAge +
                ", course=" + course +
                '}';
    }
}
